﻿
/*$(function () {
    $("#articleSearch").submit(function (event) {
        event.preventDefault();
        var form = $(this);
        $.getJSON(form.attr("action"), form.serialize(), function (data) {
            $("#articleSearch").tmpl(data).appendTo("#article-list");
        });
    });

    $("input[data-autocomplete-source]").each(function () {
        var target = $(this);
        target.autocomplete({ source: target.attr("data-autocomplete-source") });
    });
});*/

function searchFailed() {
    $("#searchresults").addClass('message-error').html("Sorry, there was a problem with the search.");
}

function showTable() {
    $("#buttonTable").show();
    $("#searchresults").removeClass('message-error');
    greenHighlight();
}

function clearAddWords() {
    $('#addInput').val('');
    $('#updateIDInput').val('');
    $('#updateWordInput').val('');
    $('#deleteInput').val('');
}

function greenHighlight() {
    var str = document.getElementById("blah").innerHTML;
    var n = str.replace("highlight", "active");
    document.getElementById("blah").innerHTML = n;
}

    $(document).ready(function () {
        $('.down').click(function () {
            var i = 0;
            $('span').each(function (index) {
                $(this).attr("id", ++i);
            })
            var id = $('.active').attr('id');
            if (id != i) {
                $('.active').addClass('highlight').removeClass('active');
                id++;
                $('#' + id).addClass('active').removeClass('highlight');
            }
            //scrollToElement($('.active'));
            $('.active').get(0).scrollIntoView();
        });
        $('.up').click(function () {
            var i = 0;
            $('span').each(function (index) {
                $(this).attr("id", ++i);
            })
            var id = $('.active').attr('id');
            if (id != 1) {
                $('.active').addClass('highlight').removeClass('active');
                id--;
                $('#' + id).addClass('active').removeClass('highlight');
            }
            //scrollToElement($('.active'));
            $('.active').get(0).scrollIntoView();
        });
    });

    function scrollToElement(ele) {
        $('html, body, div, blah').animate({ scrollTop: ele.offset().top }, 300);
    }

    /*var searchWord;
    
    $('#searchButton').on('click', function (event) {
        $.ajax({
            url: '@Url.Action("GetHighlight", "Home")',
            type: "GET",
            dataType: "text",
            success: function (data) {
                searchWord = data;
                alert(searchWord);
            },
            error: function (x, y, z) {
                alert(x + y + z);
            }
        });
    });*/

    //$('#searchButton').on('click', function (event) {
    //    alert(searchWord);
    //    highlights(searchWord);
    
    //});
    //function searchAndHighlight(searchTerm) {
    //    $('.highlighted').removeClass('highlighted');

    //    $("body:contains('" + searchTerm + "')").html($('body').html().replace(searchTerm, "<span class='highlighted'>" + searchTerm + "</span>"));

    //    if ($('.highlighted:first').length) {
    //        $(window).scrollTop($('.highlighted:first').position().top);
    //    }
    //}

    //$(document).ready(function () {
    //    $('#searchBbutton').live("click", function () {
    //        searchAndHighlight(searchWord);
    //    });
    //});
